<?php

    require_once '../include.php';
    checkLogined();
    $page = @$_REQUEST['page']?(int)$_REQUEST['page']:1;
    $sql = "select * from imooc_cate";
    $totlaRows = getResultNum($sql);
    $pageSize = 8;
    $totalPage = ceil($totlaRows/$pageSize);
    if ($page<1 || $page==null || !is_numeric($page)){
        $page = 1;
    }
    if ($page >= $totalPage){
        $page = $totalPage;
    }
    //偏移量
    $offset = ($page - 1)*$pageSize;
    $sql = "select id,cName from imooc_cate order by id asc limit {$offset},{$pageSize}";
    $rows = fetchAll($sql);
    if (!$rows){
       alertMes("对不起，没有分类，请添加！", "addCate.php");
       exit();
    }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>大大电子商务后台管理系统</title>

    <!-- BOOTSTRAP STYLES-->
    <link href="styles/css/bootstrap.css" rel="stylesheet" />
    <!-- FONTAWESOME STYLES-->
    <link href="styles/css/font-awesome.css" rel="stylesheet" />
    <!--CUSTOM BASIC STYLES-->
    <link href="styles/css/basic.css" rel="stylesheet" />
    <!--CUSTOM MAIN STYLES-->
    <link href="styles/css/custom.css" rel="stylesheet" />
    <!-- GOOGLE FONTS-->
    <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
    <!-- /. FOOTER  -->
    <!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
    <!-- JQUERY SCRIPTS -->
    <script src="scripts/js/jquery-1.10.2.js"></script>
    <!-- BOOTSTRAP SCRIPTS -->
    <script src="scripts/js/bootstrap.js"></script>
    <!-- METISMENU SCRIPTS -->
    <script src="scripts/js/jquery.metisMenu.js"></script>
    <!-- CUSTOM SCRIPTS -->
    <script src="scripts/js/custom.js"></script>
</head>
<body>
<div id="wrapper">
    <nav class="navbar navbar-default navbar-cls-top " role="navigation" style="margin-bottom: 0">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.php">大大电子商务</a>
        </div>

        <div class="header-right">
            <a href="doAdminAction.php?act=logout" class="btn btn-danger" title="Logout"><i class="fa fa-sign-out fa-2x"></i></a>
        </div>
    </nav>
    <!-- /. NAV TOP  -->
    <nav class="navbar-default navbar-side" role="navigation">
        <div class="sidebar-collapse">
            <ul class="nav" id="main-menu">
                <li>
                    <div class="user-img-div">
                        <img src="styles/img/user.png" class="img-thumbnail" />

                        <div class="inner-text">
                            欢迎您：<?php
                            if(isset($_SESSION['adminName'])){
                                echo $_SESSION['adminName'];
                            }elseif(isset($_COOKIE['adminName'])){
                                echo $_COOKIE['adminName'];
                            }
                            ?>
                            <br />
                            <td><?php echo "今天是 " . date("Y-m-d")?>日</td>
                        </div>
                    </div>

                </li>


                <li>
                    <a class="active-menu" href="index.html"><i class="fa fa-dashboard "></i>主页</a>
                </li>
                <li>
                    <a href="#"><i class="fa fa-desktop "></i>商品管理<span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level">
                        <li>
                            <a href="addPro.php"><i class="fa fa-toggle-on"></i>添加商品</a>
                        </li>
                        <li>
                            <a href="listPro.php"><i class="fa fa-bell "></i>商品列表</a>
                        </li>
                        <li>
                            <a href="listProImages.php"><i class="fa fa-bell "></i>商品图片&简介管理</a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a href="#"><i class="fa fa-yelp "></i>分类管理<span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level">
                        <li>
                            <a href="addCate.php"><i class="fa fa-coffee"></i>添加分类</a>
                        </li>
                        <li>
                            <a href="listCate.php"><i class="fa fa-flash "></i>分类管理</a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a href="#"><i class="fa fa-flash "></i>订单管理</a>
                    <ul class="nav nav-second-level">
                        <li>
                            <a href="listlist.php"><i class="fa fa-desktop "></i>订单查询</a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a href="#"><i class="fa fa-bicycle "></i>用户管理<span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level">

                        <li>
                            <a href="addUser.php"><i class="fa fa-desktop "></i>添加用户</a>
                        </li>
                        <li>
                            <a href="listUser.php"><i class="fa fa-code "></i>用户列表</a>
                        </li>


                    </ul>
                </li>
                <li>
                    <a href="#"><i class="fa fa-bicycle "></i>管理员管理<span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level">

                        <li>
                            <a href="addAdmin.php"><i class="fa fa-desktop "></i>添加管理员</a>
                        </li>
                        <li>
                            <a href="listAdmin.php"><i class="fa fa-code "></i>管理员列表</a>
                        </li>


                    </ul>
                </li>

                <li>
                    <a href="blank.html"><i class="fa fa-square-o "></i>Blank Page</a>
                </li>
            </ul>

        </div>

    </nav>
    <!-- /. NAV SIDE  -->
    <div id="page-wrapper">
        <div id="page-inner">
            <div class="row">
                <div class="col-md-12">
                    <h1 class="page-head-line">管理员告示栏</h1>
                    <h1 class="page-subhead-line">这是一些通知事项 </h1>

                </div>
            </div>
            <div class="col-md-6">
                <!--    Context Classes  -->
                <div class="panel panel-default">

                    <div class="panel-heading">
                        分类列表
                    </div>

                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table">
                                <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>分类</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                <?php foreach ($rows as $row):?>
                                    <tr>
                                        <!--这里的id和for里面的c1 需要循环出来-->
                                        <td><input type="checkbox" id="c1" class="check"><label for="c1"class="label"><?php echo $row['id'];?></label></td>
                                        <td><?php echo $row['cName'];?></td>
                                        <td align="center">
                                            <input type="button" value="修改" class="btn" onclick="editCate(<?php echo $row['id'];?>)">
                                            <input type="button"value="删除" class="btn" onclick="delCate(<?php echo $row['id'];?>)">
                                        </td>
                                    </tr>
                                <?php endforeach;?>
                                <?php if ($totlaRows > $pageSize):?>
                                    <tr>
                                        <td colspan="4" align="center"><?php echo showPage($page, $totalPage);?></td>
                                    </tr>
                                <?php endif;?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <!--  end  Context Classes  -->
            </div>
        </div>
        <!-- /. PAGE INNER  -->
    </div>
</div>

<div id="footer-sec">
    &copy; 2017 白尚林 | More Templates
</div>
<script type="text/javascript">
    function addCate(){
        window.location='addCate.php';
    }
    function editCate(id){
        window.location='editCate.php?id='+id;
    }
    function delCate(id){
        if(window.confirm("您确定要删除吗？删除之后不可以恢复哦！！！")){
            window.location='doAdminAction.php?act=delCate&id='+id;
        }
    }
</script>
</body>
</html>
